package com.open.system.controller;

import java.util.Date;	
import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.open.system.domain.LoanAboutUsDO;
import com.open.system.service.LoanAboutUsService;
import com.open.system.service.LoanAdminLogService;
import com.open.common.controller.BaseController;
import com.open.common.utils.PageUtils;
import com.open.common.utils.Query;
import com.open.common.utils.R;
/**
 * 关于我们
 */
@Controller
@RequestMapping("/system/loanAboutUs")
public class LoanAboutUsController extends BaseController {
	@Autowired
	private LoanAboutUsService loanAboutUsService;
	
	@Autowired
	private LoanAdminLogService loanAdminLogService;
	
	@GetMapping()
	@RequiresPermissions("system:loanAboutUs:loanAboutUs")
	String LoanAboutUs(){
	    return "system/loanAboutUs/loanAboutUs";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:loanAboutUs:loanAboutUs")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
		//--操作日志--开始--
		String shopId=getUser().getEmail();
		String adminName=getUser().getName();
		String Module="关于我们";
		String detail="查看了关于我们列表";
		loanAdminLogService.saveLog(shopId, adminName, Module, detail);
		//--操作日志--结束--
        Query query = new Query(params);
		List<LoanAboutUsDO> loanAboutUsList = loanAboutUsService.list(query);
		int total = loanAboutUsService.count(query);
		PageUtils pageUtils = new PageUtils(loanAboutUsList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:loanAboutUs:add")
	String add(){
	    return "system/loanAboutUs/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("system:loanAboutUs:edit")
	String edit(@PathVariable("id") Long id,Model model){
		LoanAboutUsDO loanAboutUs = loanAboutUsService.get(id);
		model.addAttribute("loanAboutUs", loanAboutUs);
	    return "system/loanAboutUs/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:loanAboutUs:add")
	public R save( LoanAboutUsDO loanAboutUs){
		loanAboutUs.setCreateTime(new Date());
		if(loanAboutUsService.save(loanAboutUs)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("system:loanAboutUs:edit")
	public R update( LoanAboutUsDO loanAboutUs){
		loanAboutUsService.update(loanAboutUs);
		//--操作日志--开始--
		String shopId=getUser().getEmail();
		String adminName=getUser().getName();
		String Module="关于我们";
		String detail="编辑了关于我们的信息";
		loanAdminLogService.saveLog(shopId, adminName, Module, detail);
		//--操作日志--结束--
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:loanAboutUs:remove")
	public R remove( Long id){
		if(loanAboutUsService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:loanAboutUs:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		loanAboutUsService.batchRemove(ids);
		return R.ok();
	}
	
}
